//Lindsay Ergenekan 
//ergenekl@onid.oregonstate.edu
//CS311-400
//Homework2 - Question7
//


#include <stdio.h> 
#include <getopt.h> 
#include <sys/utsname.h> 
#include <time.h> 
#include <sys/stat.h>

int main(int argc, char **argv)
{ 
char c; 
struct utsname uname_pointer; 
time_t time_raw_format; 
struct stat s; 
int hflag=0;
int tflag = 0; 
int fflag = 0;
int err = 0;
char *file_name;

while ((c = getopt(argc, argv, "f:th")) != -1)
    switch (c){ 
    case 'h': 
	hflag = 1;
//        printf("%d", flag);
        break;	
    case 't': 
        tflag = 1;
//        printf("%d", flag);
        break;
    case 'f':
        fflag = 1;
        file_name = optarg; 
        break;
    case '?': 
        err = 1;
        printf ("Error is: %d", err);
        break;
    }

if (hflag == 1)
    {
uname(&uname_pointer); 
printf("Hostname = %s \n", uname_pointer.nodename);
     }

if (tflag ==1)
     {
time(&time_raw_format); 
printf("The current local time: %s", 
ctime(&time_raw_format)); 
     }

if (fflag == 1)
  {
    printf("The file name is %s", optarg);
if (stat(optarg, &s) == 0) 
       { 
       
       printf("size of file '%s' is %d bytes\n" , optarg, (int) s.st_size); 
       } 
else { 
      printf("file '%s' not found\n", optarg); 
     }
  }

return 1;
}
